package com.echoplots.json.serializer;

import java.io.IOException;

import com.echoplots.json.entity.Student;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

public class StudentDeserializer extends JsonDeserializer<Student> {

    @Override
    public Student deserialize(JsonParser parser, DeserializationContext context)
            throws IOException, JsonProcessingException {
        JsonNode node = parser.getCodec().readTree(parser);
        String userName = node.get("user-name").asText();
        Student student = new Student();
        student.setUserName(userName);
        return student;
    }
}
